package com.examiner.controller;

import com.examiner.bean.test.NewTestUser;
import com.examiner.bean.vo.CommitMyTestV0;
import com.examiner.bean.vo.MyTestAndTestDBVo;
import com.examiner.bean.vo.NewTestDB;
import com.examiner.page.QueryInfo;
import com.examiner.result.Result;
import com.examiner.service.MyTestService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("myTest")
@RestController
public class MyTestController {

    @Resource
    private MyTestService myTestService;

    /**
     * 获取自评列表
     * @param id
     * @param queryInfo
     * @return
     */
    @PostMapping("/getMyTestList/{id}")
    public Result<Object> getMyTestList(@PathVariable("id") Integer id, @RequestBody QueryInfo queryInfo){
        List<MyTestAndTestDBVo> myTestList;
        int total;
        Map<String, Object> data = new HashMap<>();
        try{
            myTestList = myTestService.getMyTestList(id, queryInfo);
            total = myTestService.getMyTestListTotal(id,queryInfo);
        }catch (Exception e){
            e.printStackTrace();
            return Result.RESULT(201,"获取考评记录失败",false,null);
        }
        data.put("myTestList",myTestList);
        data.put("total",total);
        return Result.RESULT(200,"成功获取考评记录",true,data);
    }

    @PostMapping("/getNewTestUser/{id}")
    public Result<Object> getNewTestUser(@PathVariable("id")Integer id){
        NewTestUser newTestUser;
        try{
            newTestUser = myTestService.getNewTestUser(id);
        }catch (Exception e){
            e.printStackTrace();
            return Result.RESULT(201,"获取自评信息失败",false,null);
        }
        return Result.RESULT(200,"获取自评信息成功",true,newTestUser);
    }

    /**
     *获取考评信息
     * @param nid
     * @return
     */
    @PostMapping("/getMyTestInfo/{nid}")
    public Result<Object> getMyTestInfo(@PathVariable("nid")Integer nid){
        NewTestDB myTestInfo;
        try{
            myTestInfo = myTestService.getMyTestInfo(nid);
        }catch (Exception e){
            e.printStackTrace();
            return Result.RESULT(201,"获取考评信息失败",false,null);
        }
        return Result.RESULT(200,"成功获取考评信息",true,myTestInfo);
    }

    /**
     * 提交自评
     * @param commitMyTestV0
     * @return
     */
    @PostMapping("/commitMyTest")
    public Result<Object> commitMyTest(@RequestBody CommitMyTestV0 commitMyTestV0){
        try{
            myTestService.commintMyTest(commitMyTestV0);
        }catch (Exception e){
            e.printStackTrace();
            return Result.RESULT(200,"提交考评信息失败",true,null);
        }
        return Result.RESULT(200,"成功提交考评信息",true,null);
    }

    /**
     * 提交自评审核
     * @param commitMyTestV0
     * @return
     */
    @PostMapping("/commitCheckTest")
    public Result<Object> commitCheckTest(@RequestBody CommitMyTestV0 commitMyTestV0){
        try{
            myTestService.commintCheckTest(commitMyTestV0);
        }catch (Exception e){
            e.printStackTrace();
            return Result.RESULT(200,"提交考评审核信息失败",true,null);
        }
        return Result.RESULT(200,"成功提交考评审核信息",true,null);
    }


}
